package com.sk.control;

import javax.ws.rs.POST;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.sk.domain.User;
import com.sk.service.UserService;

@Controller
@RequestMapping("/user")
public class UserControl  extends BaseControl{
	@Autowired
	private UserService us;
	@POST
	@RequestMapping("/login")
	public String login(@RequestParam("uname")String uname,@RequestParam("pwd") String pwd){
		System.out.println(us);
		User u = us.findByUname(uname,pwd);
		System.out.println("login...");
		if(u!= null){
			session.setAttribute("user", u);
			System.out.println("login...success");
			return "springmvc/good/findAll";
			//return "success";
		}
		
		return "error";
	}
	@POST
	@RequestMapping("/reg")
	public String reg(@RequestParam("uname")String uname,@RequestParam("pwd") String pwd){
		boolean u = us.addUser(uname,pwd);
		if(u){
			return "login";
		}
		
		return "error";
	}

}
